package com.fesine.learn.design.pattern.creational.prototype.clone;

import java.util.Date;

/**
 * @description: 类描述
 * @author: fesine
 * @createTime:2019/4/21
 * @update:修改内容
 * @author: fesine
 * @updateTime:2019/4/21
 */
public class Pig implements Cloneable {

    private String name;

    private Date birthday;

    public Pig(String name, Date birthday) {
        this.name = name;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Pig pig = (Pig) super.clone();
        //对于引用类型需要进行深克隆,否则会产生一处修改到处生效的bug
        pig.birthday = (Date) pig.birthday.clone();
        return pig;
    }

    @Override
    public String toString() {
        return "Pig{" +
                "name='" + name + '\'' +
                ", birthday=" + birthday +
                '}'+super.toString();
    }
}
